﻿/// <reference path="../Client/bundels/libs.js" />
/// <reference path="../Client/Shared/Collection.js" />
/// <reference path="../Client/Collections/PersonCollection.js" />

describe("PersonCollection", function () {
    personDataService = {
        get: function (query) {
            return $.Deferred().resolve({list : [{ id: 1, firstName: "Cristi" }]}).promise();            
        },
        add: function (person) {
            return $.Deferred().resolve({value : 2}).promise();
        },
        edit: function (person) {
            return $.Deferred().resolve().promise();
        },
        remove: function (id) {
            return $.Deferred().resolve().promise();
        }
    }    

    var collection = new PersonCollection();    

    beforeEach(function () {
        collection.fetch();
    });

    it("fetch & get", function () {
        //act
        var result = collection.get();

        //assert
        expect(result).not.toBeNull();
        expect(result.length).toEqual(1);
    });

    it("add", function () {
        //act
        var result = collection.get();
        collection.add({ id: 0, firstName: "Test2" });

        //assert
        expect(result).not.toBeNull();
        expect(result.length).toEqual(2);
    });

    it("edit", function () {
        //act        
        collection.edit({ id: 1, firstName: "Cristian" });
        var result = collection.get();

        //assert
        expect(result).not.toBeNull();
        expect(result.length).toEqual(1);
        expect(result[0].firstName).toEqual("Cristian");
    });

    it("remove", function () {
        //act
        collection.remove(1);
        var result = collection.get();

        //assert
        expect(result).not.toBeNull();
        expect(result.length).toEqual(0);
    });
});